package sanbing.jcpplearning;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;

public class ByteBufReferenceCountExample {
    public static void main(String[] args) {
        // 使用池化分配器创建 ByteBuf
        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
        
        System.out.println("Initial refCnt: " + buffer.refCnt()); // 输出 1

        // 增加引用计数
        buffer.retain();
        System.out.println("After retain: " + buffer.refCnt()); // 输出 2

        // 减少引用计数
        buffer.release();
        System.out.println("After release: " + buffer.refCnt()); // 输出 1

        // 再次释放
        buffer.release();
        System.out.println("After final release: " + buffer.refCnt()); // 输出 0
    }
}